﻿cmake_minimum_required(VERSION 3.10.2)
include(macro.cmake)
# 项目名称, 会根据名称自动设置相关变量的值
project(ncmdump CXX)
my_seg_start(${PROJECT_NAME})
# https://cmake.org/cmake/help/latest/prop_tgt/CXX_STANDARD.html#prop_tgt:CXX_STANDARD
set(CMAKE_CXX_STANDARD 20)

set_property(GLOBAL PROPERTY USE_FOLDERS ON)
set(my_project_dir ${CMAKE_SOURCE_DIR}) # 最外层 CMakeLists.txt 的路径
set(my_bin_repos "${my_project_dir}/bin_repos") # 二进制依赖的目录

set(PRJ_SRC_LIST)
set(PRJ_HEADER_LIST)
set(PRJ_LIBRARIES)
set(PRJ_INCLUDE_DIRS) # include 目录
set(PRJ_COMPILE_OPTIONS)
set(PRJ_COMPILE_DEFINITIONS) # 预处理器宏定义
set(PRJ_COMPILE_FEATURES)
set(PRJ_LINK_OPTIONS) # ld 链接选项
set(PRJ_LINK_LIBRARIES_PRIVATE) # ld 链接库, private
set(PRJ_LINK_LIBRARIES_PUBLIC) # ld 链接库, public

# ============================= taglib
if(MY_IS_WIN_MSVC)
    list(PREPEND CMAKE_PREFIX_PATH "${my_bin_repos}/taglib/lib/cmake/taglib")
elseif(MY_IS_APPLE_CLANG)
    list(PREPEND CMAKE_PREFIX_PATH "${my_bin_repos}/taglib/lib/cmake/taglib")    
endif()

my_prt_info("[ymy taglib]: CMAKE_PREFIX_PATH => ${CMAKE_PREFIX_PATH}")
find_package(taglib REQUIRED CONFIG)
list(APPEND PRJ_LINK_LIBRARIES_PRIVATE TagLib::tag)

# ============================= zlib
if(TRUE)
  find_package("ZLIB")
  set(HAVE_ZLIB ${ZLIB_FOUND})
  if(ZLIB_FOUND)
  message(STATUS "[ymy] ZLIB FOUND")
    set(ZLIB_LIBRARIES_FLAGS -lz)
    if(NOT BUILD_SHARED_LIBS)
      # When linking TagLib statically, zlib has to be linked explicitly.
    #   set(ZLIB_INTERFACE_LINK_LIBRARIES ZLIB::ZLIB)
      list(APPEND PRJ_LINK_LIBRARIES_PRIVATE ZLIB::ZLIB)
    endif()
  endif()
endif()

# 添加要编译的 exe, 名字为 h5test1, 源文件是 Possion1.cpp
add_executable(${PROJECT_NAME}
 main.cpp cJSON.cpp aes.cpp
 ncmcrypt.cpp ncmcrypt.h color.h
 )

target_link_libraries(${PROJECT_NAME}
 PUBLIC ${PRJ_LINK_LIBRARIES_PUBLIC}
 PRIVATE ${PRJ_LINK_LIBRARIES_PRIVATE}
)

# =============================== command line arguments
if(MY_IS_APPLE_CLANG)
    set_target_properties(${PROJECT_NAME} PROPERTIES
        XCODE_GENERATE_SCHEME TRUE
        XCODE_SCHEME_ARGUMENTS "${CMAKE_BINARY_DIR}/test.ncm"
        )
endif()

# =============================== copy dlls
my_copy_prj_dlls(${PROJECT_NAME})

# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^ prj end
my_seg_end(${PROJECT_NAME})